import sys
import os
import pygame
import Entities

pygame.init()

#-----Movement-Interpolator-----

def linear_interpolate(start, stop, seconds, fps=120):
    """
    Given a start and stop vector (2 or 3 element tuple), and a time period
    at a default 30 fps, yield a sequence of vectors which interpolate
    between stop and start.
    """
    start = Numeric.array(start, Numeric.Float)
    stop = Numeric.array(stop, Numeric.Float)
    diff = stop - start
    inc = 1.0 / fps
    step = diff * inc / seconds
    current = Numeric.array(start)
    stop_second = inc * 2
    while seconds > stop_second:
        seconds -= inc
        current += step
        yield tuple(current)
    yield tuple(stop)


#-----Image-Loader-----

def load_bitmap(name, colorkey, alpha = False):
   fullname = os.path.join('data', name)
   try:
      image = pygame.image.load(fullname).convert()
   except pygame.error, message:
      print "Cannot load image: ", name
      raise SystemExit, message
   if alpha == True:
      image = image.convert_alpha()
   else:
      image = image.convert()
   if colorkey is not None:
     if colorkey is -1:
         colorkey = image.get_at((0,0))
     image.set_colorkey(colorkey)
   return image, image.get_rect()


#-----Rotator-----


def yaw(image, yaw): # this function sets the player's angle
   angle = yaw
   if angle > 360:
      angle = 0
   elif angle < 0:
      angle = 360
   #print self.angle
   center = self.x, self.y
   playyaw = transform.rotate
   image = playyaw(image, angle)
   rect = self.image.get_rect()
   rect.center = center
   return image, center

#-----Entity-class-interface-----

def load_entity(entity):
   if type(entity) != pygame.sprite.Sprite:
      pass
   else:
      print "wrong type"